from django.db import models
from django.contrib.auth.models import User

Rating_Choices = (('0', 'Not Specified'),
        ('1', 'Very Easy'),
	('2', 'Easy'),
	('3', 'Medium'),
	('4', 'Hard'),
	('5', 'Very Hard'),
)

class course(models.Model):
	courseCode = models.CharField(max_length=255) #TextField()
	courseCode.primary_key = True
	def __unicode__(self):
		return self.courseCode

class dialog(models.Model):
	dialogName = models.CharField(max_length=255) #TextField()
	course = models.ManyToManyField(course, db_column = "courseId")
	nextDialog = models.CharField(max_length=255) #TextField()
	def __unicode__(self):
		return self.dialogName

class quesAns(models.Model):
	dialog = models.ForeignKey(dialog, db_column = "dialogId")
	question = models.TextField()
	answer = models.TextField()
	qaGroup = models.IntegerField(blank=True)
	groupOrder = models.IntegerField(blank=True)
	authorRating = models.CharField(max_length=1, choices=Rating_Choices, default='0')
	def get_upload_to(self, attr):
        	return 'images/image_%d' % self.id
	media = models.ImageField(upload_to=get_upload_to, blank=True, null=True)
	def __unicode__(self):
		return self.question

class userBkView(models.Model):
	userId = models.ForeignKey(User, db_column = "userId")
	dialog = models.ForeignKey(dialog, db_column = "last_dialogId")
	quesAns = models.ForeignKey(quesAns, db_column = "last_qaId")
	last_diffFilter = models.CharField(max_length=1, choices=Rating_Choices, default='0')
	def __unicode__(self):
		return self.userId.username + " on is bookmarked at '" + self.quesAns.question + "' for " + self.dialog.dialogName
	
class userView(models.Model):
	userId = models.ForeignKey(User, db_column = "userId")
	dialog = models.ForeignKey(dialog, db_column = "dialogId")
	quesAns = models.ForeignKey(quesAns, db_column = "qaId")
	timesViewed = models.IntegerField(default=0)
	studentRating = models.CharField(max_length=1, choices=Rating_Choices, default='0')
	#understood = models.BooleanField()
	def __unicode__(self):
		return self.userId.username + " viewed '" + self.quesAns.question + "' " + str(self.timesViewed) + " times, and rated it " + self.studentRating
